<?php
namespace app\jfapp\controller;

use think\App;
use hg\apidoc\annotation as Apidoc;
use app\common\lib\Show;
use app\common\model\JfArticle as JfArticleModel;
use think\Exception;

/**
 * @Apidoc\Title("绝粪文章")
 * @Apidoc\Group("Article")
 * @Apidoc\Sort("3")
 */

class Article extends JfappBaseController
{
  protected $jf_article_model;
  public function __construct(App $app)
  {
      parent::__construct($app);
      $this->jf_article_model = new JfArticleModel();
  }

  /**
   * @Apidoc\Title("掘粪文章列表")
   * @Apidoc\Desc("获取掘粪文章列表接口")
   * @Apidoc\Author("ckmmd")
   * @Apidoc\Url("/jfapp/article/get_jf_articles")
   * @Apidoc\Method("POST")
   * @Apidoc\Tag("列表")
   * @Apidoc\Param( ref="pagingParam")
   * @Apidoc\Returned("data", type="object", desc="业务数据",
   *    @Apidoc\Returned( ref="pagingParam"),
   *    @Apidoc\Returned("list", type="array",ref="app\common\model\JfArticle\getNormalJfArticleList", desc="数据列表")
   * )
   */
  public function getJfArticles(){
    if (!$this->request->isPost()) {
      return Show::error('错误的请求');
    }
    try {
      $qurey_info = $this->request->param();
      $articles = $this->jf_article_model->getNormalJfArticleList($qurey_info);
      foreach ($articles['list'] as $article) {
        $article['user'] = $this->jf_article_model->user()->where('status', 1)->find($article['user_id']);
      }
      $articles['pageIndex'] = $qurey_info['pageIndex'] + 1;
      return Show::success($articles);
    } catch (Exception $e) {
      return Show::error($e->getMessage());
    }
  }

  /**
   * @Apidoc\Title("掘粪文章列表")
   * @Apidoc\Desc("获取掘粪文章列表接口")
   * @Apidoc\Author("ckmmd")
   * @Apidoc\Url("/jfapp/article/get_jf_article_detail")
   * @Apidoc\Method("GET")
   * @Apidoc\Tag("详情")
   * @Apidoc\Param( ref="pagingParam")
   * @Apidoc\Returned("data", type="object", desc="业务数据",
   *    @Apidoc\Returned( ref="pagingParam"),
   *    @Apidoc\Returned("data", type="Object",ref="app\common\model\JfArticle\getNormalJfArticleById", desc="数据详情")
   * )
   */
  public function getJfArticleDetail(){
    if (!$this->request->isGet()) {
      return Show::error('错误的请求');
    }
    try {
      $qurey_info = $this->request->param();
      $article = $this->jf_article_model->getNormalJfArticleById($qurey_info);
      $article['user'] = $this->jf_article_model->user()->where('status', 1)->find($article['user_id']);
      $article['html_content'] = $this->jf_article_model->content()->find($article['content_id']);
      return Show::success($article);
    } catch (Exception $e) {
      return Show::error($e->getMessage());
    }
  }
}